#! /usr/bin/env python

"""
Illustrate the effect of weak order constraints for the build (generates diagrams)

waf configure clean build -j2 --dwidth=800 --dtitle='No particular order for "waf -j2"' --dmaxtime=7.08
waf configure clean build -j2 --dwidth=800 --dtitle='Weak order for "waf -j2"' --dmaxtime=7.08
"""

def options(ctx):
	ctx.load('parallel_debug')

def configure(ctx):
	ctx.load('parallel_debug')

def build(ctx):
	for x in range(5):
		ctx(rule='sleep 1', color='GREEN', name='short task')
	ctx(rule='sleep 5', color='RED', name='long task')

import random
from waflib import Task

old = Task.set_file_constraints
def meth(lst):
	lst.sort(cmp=lambda x, y: cmp(x.__class__.__name__, y.__class__.__name__))
	#random.shuffle(lst)
	old(lst)
Task.set_file_constraints = meth

